package com.gc.baselib.utils;

import android.text.TextUtils;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DataUtils {
    public static boolean isEmpty(List dataList){
        if(dataList==null||dataList.isEmpty()){
            return true;
        }
        return false;
    }
    public static int getInt(String num){
        try{
            return  Integer.valueOf(num);
        }catch (Exception e){

        }

        return 0;
    }
    public static double getDouble(String num){
        try{
            return  Double.valueOf(num);
        }catch (Exception e){

        }
        return 0;
    }
    public static long getLong(String num){
        try{
            return  Long.valueOf(num);
        }catch (Exception e){

        }
        return 0;
    }
    public static String unicodeToString(String str) {
        String tempString = str.replace("\\x","\\u");
        Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");

        Matcher matcher = pattern.matcher(tempString);

        char ch;

        while (matcher.find()) {

            ch = (char) Integer.parseInt(matcher.group(2), 16);

            tempString = tempString.replace(matcher.group(1), ch+"" );
        }

        return tempString;

    }

    public static boolean isMobileNumber(String phoneNum) {
        String telRegex = "^((13[0-9])|(15[^4])|(16[0-9])|(18[0-9])|(17[0-8])|(147,145))\\d{8}$";
        return !TextUtils.isEmpty(phoneNum) && phoneNum.matches(telRegex);
    }
}
